using System;
using System.ComponentModel;
using System.Data.Linq.Mapping;

namespace Logging
{
    [Table]
    public class Log : INotifyPropertyChanged
    {
        private int _id;
        [Column(IsPrimaryKey = true, IsDbGenerated = true,  AutoSync = AutoSync.OnInsert)]
        public int LogId
        {
            get { return _id; }
            set { _id = value; OnPropertyChanged("LogId"); }
        }


        private DateTime _logTime;
        [Column]
        public DateTime LogTime
        {
            get { return _logTime; }
            set { _logTime = value; OnPropertyChanged("LogTime"); }
        }


        private int _level;
        [Column]
        public int Level
        {
            get { return _level; }
            set { _level = value; OnPropertyChanged("Level"); }
        }


        private string _message;
        [Column]
        public string Message
        {
            get { return _message; }
            set { _message = value; OnPropertyChanged("Message"); }
        }

        public Log()
        {
            LogTime = DateTime.Now;
            Level = Logging.Level.Info;
        }


        public override string ToString()
        {
           
            return LogTime.ToString("[MM.dd hh:mm]" + ": " + Message);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}